<template>
    <div
            style="width: 100%;background-color:#fff;line-height: 50px;display: flex;justify-content:space-between;border-bottom: #f2f2f2 solid 1px;box-sizing: "
            v-if="checkedAddress" isLink
            @click="goAddressList()">
        <span style="width: 20%;text-align: center;font-size: 16px;font-weight: bold;">送至</span>
        <span style="width: 70%;color: #666666;line-height: 20px;padding: 10px 0;">{{ addressAll ? addressAll : '请选择' }}</span>
        <span style="width: 10%"><van-icon name="ellipsis"/></span>
    </div>
    <!--    <van-cell v-if="checkedAddress" isLink @click="goAddressList()" title="收货地址">-->
    <!--        <div slot="label">-->
    <!--            <div>-->
    <!--                <span>{{ checkedAddress.name }} </span>-->
    <!--                <span>{{ checkedAddress.tel }} </span>-->
    <!--            </div>-->
    <!--            <div>-->
    <!--                {{ checkedAddress.addressDetail }}-->
    <!--            </div>-->
    <!--        </div>-->
    <!--    </van-cell>-->
</template>

<script>
    import {getLocalStorage, setLocalStorage} from "@/utils/local-storage";
    import {cartCheckout} from "@/api/api";
    import {Toast} from "vant";

    export default {
        name: "getaddress",
        data() {
            return {
                checkedAddress: {},
                addressAll: ''
            }
        },
        methods: {
            goAddressList() {
                this.$router.push({
                    path: '/user/address'
                });
            },
            init() {
                const {AddressId, CartId, CouponId} = getLocalStorage('AddressId', 'CartId', 'CouponId');

                cartCheckout({
                    cartId: CartId,
                    addressId: AddressId,
                    couponId: CouponId,
                    grouponRulesId: 0
                }).then(res => {
                    var data = res.data.data

                    this.checkedAddress = data.checkedAddress;
                    this.addressAll = this.checkedAddress.province + this.checkedAddress.city + this.checkedAddress.county + this.checkedAddress.addressDetail

                    setLocalStorage({AddressId: data.addressId, CartId: data.cartId, CouponId: data.couponId});
                }).catch(error => {
                    Toast(error.data.errmsg)

                });
            }
        },
        created() {
            this.init();
        },
    }
</script>

<style scoped>

</style>